package com.sky.service.impl;

import cn.hutool.json.JSONUtil;
import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.ReminderOrderMapper;
import com.sky.service.ReminderOrderService;
import com.sky.webSocket.WebSocketService;
import lombok.SneakyThrows;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@Service
public class ReminderOrderServiceImpl implements ReminderOrderService {
    @Resource
    private ReminderOrderMapper reminderOrderMapper;
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private WebSocketService webSocketService;

    //催单
    @SneakyThrows
    @Override
    public void reminderOrder(long orderId) {
        Orders orders = orderMapper.selectOrderById(orderId);
        if (orders != null && orders.getStatus().equals(Orders.TO_BE_CONFIRMED)&&orders.getPayStatus().equals(Orders.PAID)) {
            HashMap<Object, Object> infoMap = new HashMap<>();
            infoMap.put("type",1);
            infoMap.put("orderId",orders.getId());
            infoMap.put("content","订单号"+orders.getNumber());
            webSocketService.serverSendMessage2AllClient(JSONUtil.toJsonStr(infoMap));
        }

    }
}
